const path = require('path');
let viewPath = path.join(__dirname, './src/views');

module.exports = function(source) {
  if (path.parse(this.resourcePath).dir === viewPath && source.indexOf('export default {\n\t_code:') === -1) {
    // 该处理函数需要返回处理后的内容
    let code = source
      .replace(/[\n\r](\s\s|\t)(name|path|describe).+,?/g, '')
      .replace(/{[\n\r]+/g, '{\n');
    return source
      .replace(
        'export default {',
        `export default {\n  _code:\`${encodeURIComponent(code)}\`,`
      );
  }
  return source;
}